<template>
  <a-form :rules="postRules" :model="postFormConfig.form" @finish="submit" :label-col="{ span: 6 }"
    :wrapper-col="{ offset: 1 }" label-align="right" ref="postFormRef" :disabled="hasPerm('system:post:edit')">
    <FormCard title="编辑/新增" :back="back" subtitle="岗位信息">
      <template #extra>
        <a-button htmlType="submit" type="primary" :loading="postTable.loading" block>
          保存
        </a-button>
      </template>
      <a-row :gutter="8">
        <a-col :span="16">
          <a-card>
            <a-form-item label="岗位编码" name="postCode">
              <a-input allow-clear placeholder="请输入岗位编码" v-model:value="postFormConfig.form.postCode">
              </a-input>
            </a-form-item>
            <a-form-item label="岗位名称" name="postName">
              <a-input allow-clear placeholder="请输入岗位名称" v-model:value="postFormConfig.form.postName">
              </a-input>
            </a-form-item>
            <a-form-item label="显示顺序" name="postSort">
              <a-input allow-clear placeholder="请输入显示顺序" v-model:value="postFormConfig.form.postSort">
              </a-input>
            </a-form-item>
            <a-form-item label="状态" name="status">
              <a-input allow-clear placeholder="请输入状态（0正常 1停用）" v-model:value="postFormConfig.form.status">
              </a-input>
            </a-form-item>
            <a-form-item label="备注" name="remark">
              <a-textarea allow-clear placeholder="请输入备注" v-model:value="postFormConfig.form.remark"></a-textarea>
            </a-form-item>
            <a-form-item label="描述信息" name="postDesc">
              <a-input allow-clear placeholder="请输入描述信息" v-model:value="postFormConfig.form.postDesc">
              </a-input>
            </a-form-item>
            <a-form-item label="评论ID" name="commentId">
              <a-input allow-clear placeholder="请输入评论ID" v-model:value="postFormConfig.form.commentId">
              </a-input>
            </a-form-item>
          </a-card>
        </a-col>
        <AxExtra></AxExtra>
      </a-row>
    </FormCard>
  </a-form>
</template>

<script setup lang="ts">
import {
} from '../data/options';
import { hasPerm } from '@/utils/common/perm';
import type { Response } from '@/api/config/types';
import {
  createPost,
  updatePost,
} from '@/api/modules/system/post/post';
import { notify, } from '@/utils/table/table';
import { postList } from '../data/curd';
import {
  postFormConfig,
  postRules,
  postFormRef
} from '../data/form';
import { postTable } from '../data/table';
import AxExtra from './AxExtra.vue';

const submit = async () => {
  postTable.value.loading = true;
  let result: undefined | Response<any> = undefined
  if (postFormConfig.value.form.postId) {
    const { data } = await updatePost(postFormConfig.value.form)
    result = data
  } else {
    const { data } = await createPost(postFormConfig.value.form)
    result = data
  }
  notify(result)
  postTable.value.loading = false;
  await postList();
  back();

};

const back = () => {
  postFormConfig.value.display = false;
  postFormConfig.value.reset!();
};

</script>

<style lang="scss" scoped></style>
